using System;
using System.Collections.Generic;
using System.Text;

namespace Stratman.Utilities.NetFlix
{
    /// <summary>
    /// Contains details (synopsis, MPAA rating, actors, etc.) about a movie on NetFlix's system.
    /// </summary>
    public class MovieDetails
    {
        /// <summary>
        /// Numeric identifier for the movie.
        /// </summary>
        protected long movieID = 0;
        /// <summary>
        /// MPAA rating (PG, PG-13, R, etc.).
        /// </summary>
        protected string mpaaRating = "";
        /// <summary>
        /// Year in which the movie was released.
        /// </summary>
        protected int year = 0;
        /// <summary>
        /// Brief summary of the movie's plot.
        /// </summary>
        protected string synopsis = "";
        /// <summary>
        /// Genre to which this movie belongs.
        /// </summary>
        protected string genre = "";
        /// <summary>
        /// Average rating for the movie by other NetFlix customers.
        /// </summary>
        protected Decimal averageRating = 0;
        /// <summary>
        /// Rating for the current user predicted by NetFlix's system, based off of ratings from
        /// similar customers.
        /// </summary>
        protected Decimal predictedRating = 0;
        /// <summary>
        /// Rating (if any) given by the customer.
        /// </summary>
        protected Decimal customerRating = 0;
        /// <summary>
        /// List of directors for the movie.
        /// </summary>
        Person[] directors = null;
        /// <summary>
        /// List of actors in the movie.
        /// </summary>
        Person[] actors = null;

        /// <summary>
        /// Constructor that instantiates the various member variables based off of the JSON data
        /// that we get back from NetFlix's system.
        /// </summary>
        /// <param name="jsonDetails">
        /// Response data for the JSON call we make to NetFlix to get the movie details.
        /// </param>
        public MovieDetails(JsonMovieDetails jsonDetails)
        {
            // Instantiate the various member variables
            movieID = Convert.ToInt64(jsonDetails.id);
            mpaaRating = jsonDetails.mpaa;
            year = Convert.ToInt32(jsonDetails.year);
            synopsis = jsonDetails.synopsis;
            genre = jsonDetails.genre;
            averageRating = Convert.ToDecimal(jsonDetails.starClarityData.average);
            predictedRating = Convert.ToDecimal(jsonDetails.starClarityData.prediction);
            customerRating = Convert.ToDecimal(jsonDetails.starClarityData.rating);

            // Populate the list of actors and directors
            if (jsonDetails.directors.Length > 0)
            {
                directors = new Person[jsonDetails.directors.Length];

                for (int i = 0; i < jsonDetails.directors.Length; i++)
                    directors[i] = new Person(jsonDetails.directors[i].id, jsonDetails.directors[i].name);
            }

            if (jsonDetails.starring.Length > 0)
            {
                actors = new Person[jsonDetails.starring.Length];

                for (int i = 0; i < jsonDetails.starring.Length; i++)
                    actors[i] = new Person(jsonDetails.starring[i].id, jsonDetails.starring[i].name);
            }
        }

        /// <summary>
        /// MPAA rating (PG, PG-13, R, etc.).
        /// </summary>
        public string MpaaRating
        {
            get
            {
                return mpaaRating;
            }
        }

        /// <summary>
        /// Year in which the movie was released.
        /// </summary>
        public int Year
        {
            get
            {
                return year;
            }
        }

        /// <summary>
        /// Brief summary of the movie's plot.
        /// </summary>
        public string Synopsis
        {
            get
            {
                return synopsis;
            }
        }

        /// <summary>
        /// Genre to which this movie belongs.
        /// </summary>
        public string Genre
        {
            get
            {
                return genre;
            }
        }

        /// <summary>
        /// Average rating for the movie by other NetFlix customers.
        /// </summary>
        public Decimal AverageRating
        {
            get
            {
                return averageRating;
            }
        }

        /// <summary>
        /// Rating for the current user predicted by NetFlix's system, based off of ratings from
        /// similar customers.
        /// </summary>
        public Decimal PredictedRating
        {
            get
            {
                return predictedRating;
            }
        }

        /// <summary>
        /// Rating (if any) given by the customer.
        /// </summary>
        public Decimal CustomerRating
        {
            get
            {
                return customerRating;
            }
        }

        /// <summary>
        /// List of directors for the movie.
        /// </summary>
        public Person[] Directors
        {
            get
            {
                return directors;
            }
        }

        /// <summary>
        /// List of actors in the movie.
        /// </summary>
        public Person[] Actors
        {
            get
            {
                return actors;
            }
        }
    }
}
